#include "Sqlite.hpp"
#include <cassert>
#include<vector>
int Caalback(void* arg,int cal,char** result,char** fields_name)
{
    std::vector<std::string>* name_arry = static_cast<std::vector<std::string>*>(arg);
    name_arry->push_back(result[0]);
    return 0;
}
int main()
{
    SqliteHelper helper("./test.db");
    // 1 打开数据库
    assert(helper.Open());
    // 2 创建学生表
    // std::string create_sql = "create table stu(sn int primary key,name varchar(20),age int);";
    // assert(helper.Exec(create_sql, nullptr, nullptr));
    // 3 添加学生信息
    // std::string insert_sql = "insert into stu values(1,'小明',18),(2,'小张',19),(3,'小陈',20);";
    // assert(helper.Exec(insert_sql, nullptr, nullptr));
    // 4 修改学生信息
    // const char* update_sql = "update stu set name = '厉害哥' where sn=1";
    // assert(helper.Exec(update_sql,nullptr,nullptr));
    //5 删除学生信息
    // std::string delete_sql="delete from stu where sn=3;";
    // assert(helper.Exec(delete_sql,nullptr,nullptr));
    //6 查找学生信息
    std::vector<std::string> arry;
    std::string select_sql = "select name from stu;";
    helper.Exec(select_sql,Caalback,&arry);
    for(auto & e:arry)
    {
        std::cout<<e<<std::endl;
    }
    helper.Close();
}
